package com.winit.rabbitmq;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

    @Bean
    public Jackson2JsonMessageConverter jsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    @Value("${ucloud_node_exchange}")
    private String ucloud_node_exchange;

    private final String NODE_QUEUE=RabbitMqConsts.NODE_QUEUE;

    private final String ROUTE_KEY=RabbitMqConsts.NODE_ROUTE;




    @Bean
    DirectExchange nodeExchange(){
        return new DirectExchange(ucloud_node_exchange);
    }

    @Bean
    public Queue nodeQueue(){
        return new Queue(NODE_QUEUE);
    }


    @Bean
    Binding bindNodeExchange(Queue nodeQueue, DirectExchange nodeExchange){
        return BindingBuilder.bind(nodeQueue).to(nodeExchange).with(ROUTE_KEY);
    }



}
